﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Timers;
using System.IO;
using System.Threading;
using OpenExpressApp.MetaModel.Audit;
using OpenExpressApp.Library.Audit;

namespace OpenExpressApp.Server.WPFHost
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            HostWindow host = new HostWindow();
            host.Show();

            Unity.Instance.RegisterInstance<ICommonConnectionString>(new CommonConnectionString());
            AuditLogService.SetProvider(new ServerAuditLogProvider());
        }

        #region CommonConnectionString

        private class CommonConnectionString : ICommonConnectionString
        {
            public static readonly bool DEBUGING_BY_LOCAL;

            static CommonConnectionString()
            {
                try
                {
                    DEBUGING_BY_LOCAL = System.IO.File.Exists("C:\\GIX_DEBUGGING");
                }
                catch { }
            }

            public static string GetConnectionString(bool isGix4)
            {
                if (DEBUGING_BY_LOCAL)
                {
                    return isGix4 ? ConnectionStringNames.GIX4_local : ConnectionStringNames.BQNorm_local;
                }
                return isGix4 ? ConnectionStringNames.GIX4 : ConnectionStringNames.BQNorm;
            }

            #region ICommonConnectionString Members

            public string Value
            {
                get
                {
                    return GetConnectionString(true);
                }
            }

            #endregion

            /// <summary>
            /// 数据库使用的连接字符串名
            /// 统一管理Connection字符串
            /// </summary>
            public class ConnectionStringNames
            {
                public static readonly string GIX4 = "BusinessDBName";
                public static readonly string BQNorm = "BQNormDBName";
                public static readonly string GIX4_local = "BusinessDBName_local";
                public static readonly string BQNorm_local = "BQNormDBName_local";
            }
        }

        #endregion

    }
}
